package cn.com.ddapp.ddm.api;

import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.GetBuilder;
import com.zhy.http.okhttp.builder.PostFormBuilder;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.ddapp.ddm.inter.OkUtilCallback;
import cn.com.ddapp.ddm.util.NetUtils;
import cn.com.ddapp.ddm.util.OKHttpUtils.FileFormBuilder;
import cn.com.ddapp.ddm.util.OKHttpUtils.MyOKHttpUtils;
import cn.com.ddapp.ddm.util.StringUtils;
import cn.com.ddapp.ddm.util.TLog;


/**
 * Created by caopenghui on 2016-07-30.
 */
public class OKUtilAPI {
//    public static final String baseUrl = "http://116.62.206.37:8083/ddm";
//    public static final String baseUrl = "http://139.224.69.131:8080/";
//    public static final String imgBaseUrl = "http://139.224.69.131:9090/";
//    public static final String baseUrl = "http://192.168.1.200:8084/ddm/app/accept/add.api";
//    public static final String baseUrl = "http://192.168.1.200:8084/ddm/";   //本地数据库
    public static final String baseUrl = "http://mall.jxezt.cn/";
    public static final String imgBaseUrl = "http://static.mall.jxezt.cn/";
    public static final String imgBaseUrl1 ="http://static.erp.jxezt.cn/";

    public static final String getVersion =baseUrl+ "/app/version/getVersion.api";//ATM版本号
    public static final String evalList  =  baseUrl+ "/app/order/evalList.api";//订单评价的商品列表获取
    public static final String login  =  baseUrl+ "/app/user/login.api";//登录
    public static final String regist  =  baseUrl+ "/app/user/regist.api";//注册
    public static final String getCode  =  baseUrl+ "/app/user/sendCode.api";//获取验证码
    public static final String chkCode  =  baseUrl+ "/app/user/chkCode.api";//验证
    public static final String resetPwd  =  baseUrl+ "/app/user/resetPwd.api";//重设密码

    public static final String shopList=baseUrl+ "/app/shopcar/list.api";//获取购物车列表
    public static final String clearCars=baseUrl+ "/app/order/clearing.api";//购物车结算
    public static final String addOrders=baseUrl+ "/app/order/add.api";//生成订单
    public static final String orderList=baseUrl+ "/app/order/list.api";//订单列表
    public static final String orderCancel = baseUrl+ "/app/order/cancel.api";//取消订单
    public static final String orderAccept = baseUrl+ "/app/order/accept.api";//确认收货
    public static final String delCars = baseUrl+ "/app/shopcar/del.api";//删除购物车
    public static final String editCars = baseUrl+ "/app/shopcar/save.api";//加入/更新购物车
    public static final String eval     = baseUrl+ "/app/order/evaluate.api";//订单评价
    public static final String order_tips     = baseUrl+ "/app/order/tips.api";//提醒发货
    public static final String order_detail   = baseUrl+ "/app/order/detail.api"; //订单详情
    public static final String updateUser   = baseUrl+ "/app/user/updateUser.api"; //更新用户资料
    public static final String getCoupons  =  baseUrl+ "/app/user/coupons.api";//获取优惠券列表
    public static final String delCoupons  =  baseUrl+ "/app/user/couponsDel.api";//删除优惠券
    public static final String homeurl  =  baseUrl+ "/app/index.api";//首页
    public static final String atmhomeurl  =  baseUrl+ "/app/atmIndex.api";//atm首页
    public static final String limitGo  =  baseUrl+ "/app/flashSale.api";//限时抢购
    public static final String HUOCommid  =baseUrl+ "/app/promotion/list.api";//活动产品
    public static final String CommidUrl  =baseUrl+ "/app/goods/detail.api";//商品详情的网址
    public static final String CommidUrl_1 =baseUrl+ "/app/goods/detail.api";//商品详情的网址
    public static final String CATURL=baseUrl+ "/app/shopcar/save.api";//加入购物车
    public static final String SHOUC=baseUrl+ "/app/collection/save.api";//加入收藏
    public static final String QUXIAO=baseUrl+ "/app/collection/del.api";//取消收藏
    public static final String ShouAddress=baseUrl+ "/app/accept/list.api";//会员收获地址
    public static final String QUICK=baseUrl+ "/app/order/buyNow.api";//立即生成订单
    public static final String goodUrl  =  baseUrl+ "/app/index.api";//
    public static final String CITYLIST=baseUrl+ "/app/addrGroup.api";//地址列表
    public static final String CITYLIST_URL=baseUrl+ "/app/getProvinceAndCity.api";//省市
    public static final String indexaddId=baseUrl+ "/app/getLocation.api";//首页获取地址ID
    public static final String getDefAdd=baseUrl+ "/app/accept/getDefault.api";//获取默认地址


    public static final String getART  =  baseUrl+ "/app/art.api";
    public static final String getFeeds  =  baseUrl+ "/app/user/feedback.api";
    public static final String getCollection  =  baseUrl+ "/app/collection/list.api";//会员资料,参数为userId
    public static final String getUser  =  baseUrl+ "/app/user/info.api";//会员资料,参数为userId
    public static final String loadArea  =  baseUrl+ "/app/accept/loadArea.api";//获取地区的列表,parentId int[N]  上级ID 默认获取顶层区域的ID
    public static final String getAddress  =  baseUrl+ "/app/accept/list.api";//得到收货地址,参数为userId
    public static final String addAddress  =  baseUrl+ "/app/accept/add.api";//新增收货地址
    public static final String deleteAddress  =  baseUrl+ "/app/accept/del.api";//删除收货地址,userId,id
    public static final String setDefaultAddress  =  baseUrl+ "/app/accept/setDefault.api";//设置默认收货地址,userId,id
    public static final String goodsort  =  baseUrl+ "/app/goodsSort/list.api";//获取分类列表
    public static final String getGoodsort  =  baseUrl+ "/app/goodsSort/list.api";//获取下级分类列表
    public static final String circlelist  =  baseUrl+ "/app/circle/list.api";//获取发现列表
    public static final String savecircle  =  baseUrl+ "/app/circle/save.api";//发布分享
    public static final String nearstore  =  baseUrl+ "/app/shopDis/list.api";//配送点
    public static final String myshare  =  baseUrl+ "/app/circle/myZone.api";//分享专区
    public static final String alterLoginPwd = baseUrl+ "/app/user/updateLoginPwd.api";//修改登录密码
    public static final String bindMobile = baseUrl+ "/app/user/bindMobile.api";//绑定手机
    public static final String updateMobile = baseUrl+ "/app/user/updateMobile.api";//更新手机
    public static final String sendVerifyCode = baseUrl+ "/app/user/sendCode.api";//发送验证码
    public static final String goodclassify = baseUrl+ "/app/goods/get.api";//商品列表
    public static final String verify = baseUrl+ "/app/user/chkCode.api";//验证
    public static final String saveNameAuth = baseUrl+ "/app/user/saveNameAuth.api";//实名认证
    public static final String nameAuthOk = baseUrl+ "/app/user/chkNameAuth.api";//验证会员实名是否正确
    public static final String updateEmail = baseUrl+ "/app/user/updateEmail.api";//绑定邮箱
    public static final String condition = baseUrl+ "/app/goods/condition.api";//商品条件筛选
    public static final String goodsearch = baseUrl+ "/app/goods/likeGoodsName.api";//商品名称模糊查询
    public static final String RTLIST=baseUrl+ "/app/order/rtType.api";//退货原因类型列表
    public static final String RT=baseUrl+ "/app/order/rt.api";//申请退货
    public static final String afterDetail = baseUrl+ "/app/order/asDetail.api";//售后详情
    public static final String goodsFollow = baseUrl+ "/app/collection/goodsSave.api";//收藏多个商品

    public static final String moneyDetail = baseUrl+ "/app/account/walletRecord.api";//财务明细
    public static final String getCard = baseUrl+ "/app/account/list.api";//查看绑定卡列表
    public static final String addBank = baseUrl+ "/app/account/addBank.api";//添加银行卡
    public static final String addAlipay = baseUrl+ "/app/account/addAlipay.api";//添加支付宝
    public static final String settingPwd = baseUrl+ "/app/user/resetPwd.api";//设置支付密码
    public static final String updatePayPwd = baseUrl+ "/app/user/updatePayPwd.api";//设置支付密码
    public static final String mlist = baseUrl+ "/app/user/mlist.api";//会员消息列表
    public static final String notReadMsg = baseUrl+ "/app/user/msgNotReadCount.api";//获取会员未读取的信息总数
    public static final String mdetail = baseUrl+ "/app/user/mdetail.api";//会员消息详情
    public static final String del = baseUrl+ "/app/account/del.api";//删除银行卡
    public static final String bankList = baseUrl+ "/app/account/bankList.api";//银行卡列表
    public static final String udefaultBank = baseUrl+ "/app/account/udefaultBank.api";//设置默认银行地址
    public static final String defaultBank = baseUrl+ "/app/account/defaultBank.api";//获取默认银行/支付宝的信息
    public static final String tixian = baseUrl+ "/app/account/wd.api";//会员提现
    public static final String brand=baseUrl+ "/app/brand/list.api";  //品牌狂欢
    public static final String promotio=baseUrl+ "/app/promotion/everyDay.api";  //天天特价
    public static final String art = baseUrl+ "/app/art.api";//关于我们/帮助说明/活动规则/客服热线/我的钱包-规则说明

    public static final String ORDER_PRICE = baseUrl+ "/app/order/getOrderAmountByOrderNo.api";//获取订单金额
    public static final String USER_RECHARGE = baseUrl+ "/app/userRecharge/rechargeStatus.api";//查充值状态 rechargeNo 返回status =true 为成功，false 失败
    public static final String SCAN_CALLBACK = baseUrl+"/weixin/scanCallback.api";//微信扫码回调
    public static final String WEIXINPAY_CALLBACK = baseUrl+"/weixin/paycallback.api";//微信支付回调
    public static final String ALIPAYPAY_CALLBACK = baseUrl+"/alipay/callback.api";//支付宝支付回调
    public static final String WALLET_PAY = baseUrl+ "/app/user/pay2wallet.api";//钱包回调

    public static final String ALYPAY_CODE = baseUrl+ "/alipayScan.api";//获取支付宝扫码连接
    public static final String ALYPAY_CALLBACK = baseUrl+ "/checkAlipayIsPay.api";//扫码回调请求

    public static final String WEIXIN_RECHARGEPAY_CALLBACK = baseUrl+"/weixin/rechargePaycallback.api";//微信充值回调
    public static final String RECHARGE_SCAN_CALLBACK = baseUrl+"/weixin/rechargeScanCallback.api";//微信充值回调
    public static final String ALIPAY_RECHARGEPAY_CALLBACK = baseUrl+"/alipay/rechargePaycallback.api";//支付宝充值回调
    public static final String userRecharge =baseUrl+ "/app/userRecharge/recharge.api";//充值生成充值订单
    public static final String otherLogin =baseUrl+ "/app/user/otherLogin.api";//第三方登录
    public static final String countStamp =baseUrl+ "app/accept/urgentCount.api";//计算加急邮费 areaIds [Y] 有加急邮费的区域ID date [Y] 加急的时间 hour [Y] 加急选择的时间
    public static final String ATMCODE = baseUrl+"app/getCityByCode.api";//根据ATM编码获取地区地址ID
    public static final String showArticle = baseUrl+"app/showArticle.api";//Banner文章 id
    public static final String ADList = baseUrl+"app/setupImg.api?adType=4";//广告
    public static final String ATM = baseUrl + "app/addrCode.api";//通过机器码获取地址

    public static void get(String url,String params,OkUtilCallback callback){
        TLog.log("接口请求全路径",url+"?"+params);
      GetBuilder builder =  OkHttpUtils.get().url(url);
        //username=hyman
        if(!StringUtils.isEmpty(params)){
            String[] parmss = params.split("&");
            for(String p: parmss){
                String[] pMap = p.split("=");
                if(pMap.length==1){
                    continue;//只传键值
                }
                builder.addParams(pMap[0],pMap[1]);
            }
        }
        builder.build().execute(callback);
    }


    public static void post(String url,String params,OkUtilCallback callback){
        TLog.log("接口请求全路径",url+"?"+params);
        PostFormBuilder builder =  OkHttpUtils.post().url(url);
        //username=hyman
        if(!StringUtils.isEmpty(params)){
            String[] parmss = params.split("&");
            for(String p: parmss){
                String[] pMap = p.split("=");
                if(pMap.length==1){
                    continue;//只传键值
                }
                builder.addParams(pMap[0],pMap[1]);
            }
        }
        builder.build().execute(callback);
    }
    public static void postNObase(String url,String params,OkUtilCallback callback){
        TLog.log("接口请求全路径",url+"?"+params);
        PostFormBuilder builder =  OkHttpUtils.post().url(url);
        //username=hyman
        if(!StringUtils.isEmpty(params)){
            String[] parmss = params.split("&");
            for(String p: parmss){
                String[] pMap = p.split("=");
                if(pMap.length==1){
                    continue;//只传键值
                }
                builder.addParams(pMap[0],pMap[1]);
            }
        }
        builder.build().execute(callback);
    }

    public static void file(String url, String params, OkUtilCallback callback, HashMap<String,List<File>> files){
        TLog.log("接口请求全路径(文件上传)",url+"?"+params);
        FileFormBuilder builder = (FileFormBuilder) MyOKHttpUtils.file().url(url);
        //username=hyman
        if(!StringUtils.isEmpty(params)){
            String[] parmss = params.split("&");
            for(String p: parmss){
                String[] pMap = p.split("=");
                if(pMap.length==1){
                    continue;//只传键值
                }
                builder.addParams(pMap[0],pMap[1]);
            }
        }
        if(files!=null){
            for(String key: files.keySet()){
                List<File> fileList = files.get(key);
                if(fileList!=null && fileList.size()>0){
                    for(File file : fileList){
                        builder.addFile(key,"",file);
                    }
                }
            }
        }
        builder.build().execute(callback);
    }

    public static void postfile(String url, String params, OkUtilCallback callback, HashMap<String,List<File>> files){
        TLog.log("接口请求全路径(文件上传)",url+"?"+params);
        FileFormBuilder builder = (FileFormBuilder) MyOKHttpUtils.file().url(url);
        //username=hyman
        if(!StringUtils.isEmpty(params)){
            String[] parmss = params.split("&");
            for(String p: parmss){
                String[] pMap = p.split("=");
                if(pMap.length==1){
                    continue;//只传键值
                }
                builder.addParams(pMap[0],pMap[1]);
            }
        }
        SimpleDateFormat format=new SimpleDateFormat("HH:mm:ss");
        format.format(new Date());
        if(files!=null){
            for(String key: files.keySet()){
                List<File> fileList = files.get(key);
                if(fileList!=null && fileList.size()>0){
                    for(File file : fileList){
                        System.out.println("huaG="+file.getPath());
                        builder.addFile(key,"format.jpg",file);
                    }
                }
            }
        }
        builder.build().execute(callback);
    }

    public static String saveNoImg(
                                             Map<String, Object> params) {
        return NetUtils._Nullpost(
                baseUrl+savecircle, params);
    }

}
